package com.ruoyi.project.wenyanwen.generatelog.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.wenyanwen.generatelog.domain.DbGenerateLog;
import com.ruoyi.project.wenyanwen.generatelog.service.IDbGenerateLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 数据包浏览Controller
 *
 * @author shixiangwen
 * @date 2020-09-27
 */
@Controller
@RequestMapping("/wenyanwen/generatelog")
public class DbGenerateLogController extends BaseController {

    private String prefix = "wenyanwen/generatelog";

    @Autowired
    private IDbGenerateLogService dbGenerateLogService;

    @RequiresPermissions("wenyanwen:generatelog:view")
    @GetMapping()
    public String generatelog() {
        return prefix + "/generatelog";
    }

    /**
     * 查询数据包浏览列表
     */
    @RequiresPermissions("wenyanwen:generatelog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DbGenerateLog dbGenerateLog) {
        startPage();
        List<DbGenerateLog> list = dbGenerateLogService.selectDbGenerateLogList(dbGenerateLog);
        return getDataTable(list);
    }

    /**
     * 导出数据包浏览列表
     */
    @RequiresPermissions("wenyanwen:generatelog:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DbGenerateLog dbGenerateLog) {
        List<DbGenerateLog> list = dbGenerateLogService.selectDbGenerateLogList(dbGenerateLog);
        ExcelUtil<DbGenerateLog> util = new ExcelUtil<DbGenerateLog>(DbGenerateLog.class);
        return util.exportExcel(list, "generatelog");
    }

    /**
     * 新增数据包浏览
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存数据包浏览
     */
    @RequiresPermissions("wenyanwen:generatelog:add")
    @Log(title = "数据包浏览", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DbGenerateLog dbGenerateLog) {
        return toAjax(dbGenerateLogService.insertDbGenerateLog(dbGenerateLog));
    }

    /**
     * 修改数据包浏览
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        DbGenerateLog dbGenerateLog = dbGenerateLogService.selectDbGenerateLogById(id);
        mmap.put("dbGenerateLog", dbGenerateLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存数据包浏览
     */
    @RequiresPermissions("wenyanwen:generatelog:edit")
    @Log(title = "数据包浏览", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DbGenerateLog dbGenerateLog) {
        return toAjax(dbGenerateLogService.updateDbGenerateLog(dbGenerateLog));
    }

    @RequiresPermissions("wenyanwen:generatelog:edit")
    @Log(title = "上传数据包", businessType = BusinessType.UPDATE)
    @PostMapping("/upload")
    @ResponseBody
    public AjaxResult upload(Long id) {
        return toAjax(dbGenerateLogService.upload(id));
    }

    /**
     * 删除数据包浏览
     */
    @RequiresPermissions("wenyanwen:generatelog:remove")
    @Log(title = "数据包浏览", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(dbGenerateLogService.deleteDbGenerateLogByIds(ids));
    }
}
